<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>商品营销标签</title>
    <link rel="stylesheet" href="/static/lib/layui-v2.5.6/layui-v2.5.6/layui/css/layui.css">
    <script src="https://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script>
    <script src="/static/lib/bootstrap-3.3.7/dist/js/bootstrap.js"></script>
    <link rel="stylesheet" href="/static/lib/bootstrap-3.3.7/dist/css/bootstrap.css">
    <style>
        .SellLabel_delbtn{
            cursor: pointer;
        }
    </style>
</head>
<body>

    
    
    <div class="panel panel-default">
        <div class="panel-heading">营销标签商品列表<button style="float: right;" class="layui-btn layui-btn-sm layui-btn-radius SellLabel_addbtn">添加商品分类</button></div>
        <div class="panel-body">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>主标题</th>
                        <th>副标题</th>
                        <th>操作</th>
                    </tr>
                </thead>
                <tbody class="SellLabel_info">
                </tbody>
            </table>
        </div>


    </div>


<!-- //营销标签的增加和修改 -->
<div id="SellLabelUpdate" style="display: none;margin-top: 30px;">
    <form class="layui-form">
        
        <div class="layui-form-item">
            <label class="layui-form-label">主标题</label>
            <div class="layui-input-inline">
                <input id="SellLabeltitle" type="text" name="SellLabeltitle" required lay-verify="required" placeholder="请输入营销主标题" class="layui-input">
            </div>
        </div>
        
        <div class="layui-form-item">
            <label class="layui-form-label">副标题</label>
            <div class="layui-input-inline">
                <input id="SellLabelsubtitle" type="text" name="SellLabelsubtitle" required lay-verify="required" placeholder="请输入营销副标题" class="layui-input">
            </div>
        </div>
    </form>
</div>








    <script src="/static/lib/layui-v2.5.6/layui-v2.5.6/layui/layui.js"></script>
    <script>
        
        SellLabelList()
        

        layui.use(['table','element',], function(){
            var $ = layui.jquery;
            var table = layui.table;
            var element = layui.element;
            
                $(document).off('click','.SellLabel_addbtn').on('click','.SellLabel_addbtn',function () {
                    layer.open({
                        type: 1,
                        skin: 'layui-layer-rim', //加上边框
                        area: ['660', '500'], //宽高
                        title: '增加商品分类',
                        btn: ['添加','关闭'],
                        content: $('#SellLabelUpdate'),
                        yes:function(index){
                            var title = $("#SellLabeltitle").val()
                            var subtitle = $("#SellLabelsubtitle").val()
                            if (title == '' || title == undefined ||title == null) {
                                layer.msg('主标题不能为空')
                            }else {
                                $.ajax({
                                    type: "post",
                                    url: "/admin/commoditySellLabel/addLabel",
                                    data: {title: title,subtitle, subtitle},
                                    dataType: "json",
                                    async: false,
                                    
                                })
                                SellLabelList()
                                layer.close(index);
                            }
                        }
                    })
                })

                $(document).off('click','.SellLabel_delbtn').on('click','.SellLabel_delbtn',function () {
                    
                    var labelId = $(this).closest('tr').attr('in');
                    layer.confirm('真的删除行么', function(index){
                        $.ajax({
                            type: "post",
                            url: "/admin/commoditySellLabel/delLabel",
                            data: {labelId: labelId},
                            dataType: "json",
                            async: false,
                            
                        })
                        SellLabelList()
                        layer.close(index);
                    })
                    
                })




           


        });



        function SellLabelList() {
                $.ajax({
                    type: "get",
                    url: "/admin/commoditySellLabel",
                    data: '',
                    dataType: "json",
                    // async: false,
                    success: function(res){
                        var tag = ''
                        for (let i = 0; i < res.length; i++) {
                            // tag1 = '<li in="'+ res[i].id +'" class="list-group-item"><span class="badge SellLabel_delbtn">删除</span>'+ res[i].title +'</li>'
                            tag1 = '<tr in="'+ res[i].id +'"><td>'+ res[i].title +'</td><td>'+ res[i].subtitle +'</td><td><span class="badge SellLabel_delbtn">删除</span></td></tr>'
                            tag += tag1
                        }
                        $('.SellLabel_info').html(tag) 
                    }
                })
            } 
        
    </script>
</body>
</html>